<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ taglib uri ="http://shiro.apache.org/tags" prefix="shiro"%>
<%
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ request.getContextPath() + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>course home</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>


<link rel="stylesheet" type="text/css"
	href="<%=basePath%>resources/jquery/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="<%=basePath%>resources/jquery/themes/icon.css">
<script type="text/javascript"
	src="<%=basePath%>resources/jquery/jquery.min.js"></script>
<script type="text/javascript"
	src="<%=basePath%>resources/jquery/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="<%=basePath%>resources/jquery/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>

	<h1><a href="/siyuan/logout.shtml">退出</a></h1>
	<h1><a href="/siyuan/home.shtml">返回home页面</a></h1>
	


<table id="dg" title="课程管理页面" class="easyui-datagrid" style="width:1300px;height:300px"
		url="/siyuan/all_course.shtml"
		toolbar="#toolbar"
		rownumbers="true" fitColumns="true" singleSelect="true">
	<thead>
		<tr>
			<th field="id" width="25">课程编号</th>
			<th field="name" width="100">课程名字</th>
			<th field="teacher" width="50">老師</th>
			<th field="hour" width="25">时长/小时</th>
			<th field="classroom" width="50">教室</th>
			<th field="time" width="25">上课时间</th>
			<th field="department" width="50">部门</th>
			<th field="type" width="50">课程类型</th>
			<th field="day" width="50">周</th>
		</tr>
	</thead>
</table>
<div id="toolbar">
	<a  class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">添加课程</a>
	<a  class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">修改课程</a>
	<a  class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除课程</a>
</div>



<div>
<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
        closed="true" buttons="#dlg-buttons">
    <div class="ftitle">课程信息输入</div>
    
   <form id="fm" method="post">
        <div class="fitem">
            <label>名字:</label>
            <input name="name" class="easyui-validatebox" >
        </div>
        <div class="fitem">
            <label>teacherId:</label>
            <input name="teacherId" class="easyui-validatebox" >
        </div>
        <div class="fitem">
            <label>courseTime:</label>
            <input name="courseTime" class="easyui-validatebox">
        </div>
                <div class="fitem">
            <label>classroom:</label>
            <input name="classroom" class="easyui-validatebox" >
        </div>
                <div class="fitem">
            <label>type:</label>
            <input name="type" class="easyui-validatebox" >
        </div>
                <div class="fitem">
            <label>collegeId:</label>
            <input name="collegeId" class="easyui-validatebox" >
        </div>
                <div class="fitem">
            <label>courseweek:</label>
            <input name="courseweek" class="easyui-validatebox" >
        </div>
                <div class="fitem">
            <label> time:</label>
            <input name=" time" class="easyui-validatebox" >
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a  class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">保存</a>
    <a  class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>
</div>


<div>
<div id="dlg1" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
        closed="true" buttons="#dlg-buttons">
    <div class="ftitle">课程信息输入</div>
    
   <form id="fm1" method="post">
        <div class="fitem">
            <label>名字:</label>
            <input name="name" class="easyui-validatebox" >
        </div>
        <div class="fitem">
            <label>teacherId:</label>
            <input name="teacherId" class="easyui-validatebox" >
        </div>
        <div class="fitem">
            <label>courseTime:</label>
            <input name="courseTime" class="easyui-validatebox">
        </div>
                <div class="fitem">
            <label>classroom:</label>
            <input name="classroom" class="easyui-validatebox" >
        </div>
                <div class="fitem">
            <label>type:</label>
            <input name="type" class="easyui-validatebox" >
        </div>
                <div class="fitem">
            <label>collegeId:</label>
            <input name="collegeId" class="easyui-validatebox" >
        </div>
                <div class="fitem">
            <label>courseweek:</label>
            <input name="courseweek" class="easyui-validatebox" >
        </div>
                <div class="fitem">
            <label> time:</label>
            <input name=" time" class="easyui-validatebox" >
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a  class="easyui-linkbutton" iconCls="icon-ok" onclick="updateUser()">修改</a>
    <a  class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>
</div>











<script type="text/javascript">  

function newUser(){
    $('#dlg').dialog('open').dialog('setTitle','新学生');
    $('#fm').form('clear');

};


function saveUser(){
    $('#fm').form('submit',{
        url: '/siyuan/insert.shtml',
        onSubmit: function(){
            return $(this).form('validate');
        },
        success: function(result){
            var result = eval('1');
            if (result.errorMsg){
                $.messager.show({
                    title: 'Error',
                    msg: result.errorMsg
                });
            } else {
                $('#dlg').dialog('close');        // close the dialog
                $('#dg').datagrid('reload');    // reload the user data
            }
        }
    });
};

function editUser(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
	    $('#dlg1').dialog('open').dialog('setTitle','修改');
	    $('#fm1').form('load',row);  
	    url = '/siyuan/update.shtml?courseid='+row.id;
	    
	}
}

function updateUser(){
    $('#fm1').form('submit',{
        url: url,
        onSubmit: function(){
            return $(this).form('validate');
        },
        success: function(result){
            var result = eval('1');
            if (result.errorMsg){
                $.messager.show({
                    title: 'Error',
                    msg: result.errorMsg
                });
            } else {
                $('#dlg1').dialog('close');        // close the dialog
                $('#dg').datagrid('reload');    // reload the user data
            }
        }
    });
};

function destroyUser(){
    var row = $('#dg').datagrid('getSelected');
    if (row){
        $.messager.confirm('Confirm','确定删除?',function(r){
            if (r){
                $.post('/siyuan/delete.shtml',{id:row.id},function(result){
                    if (result = eval('1')){
                        $('#dg').datagrid('reload');    // reload the user data
                    } else {
                        $.messager.show({    // show error message
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    }
                },'json');
            }
        });
    }
}

</script>



<!-- <div id="tb" style="padding:3px">			 -->
<!-- 	<span>课程编号:</span> -->
<!-- 	<input id="courseid" > -->
	
<!-- 	<span>课程名字:</span> -->
<!-- 	<input id="courseName" > -->
	
<!-- 	<span>学院编号:</span> -->
<!-- 	<input id="collegeid" > -->

<!-- 	<a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()">Search</a> -->
<!-- </div> -->

	
</body>
</html>